
# 计算月连续表现
def cal_month_inc_num(raw_df):

    for index, item in raw_df.iterrows():

        df = raw_df[:index]

        # 最后一个数据
        item = df.iloc[-1]

        # 计算连续上涨或下跌周期
        if (item['month_pct'] > 0):
            # 计算上涨
            count = 1
            pct_sum = item['month_pct']
            try:
                while(df.iloc[-1*count - 1].month_pct >= 0):
                    pct_sum += df.iloc[-1*count - 1].month_pct
                    count += 1
            except IndexError:
                pass

            raw_df.loc[index, 'inc_num'] = count
            raw_df.loc[index, 'pct_sum'] = pct_sum

        elif (item['month_pct'] < 0):
            # 计算下跌
            count = 1
            pct_sum = item['month_pct']
            try:
                while(df.iloc[-1*count - 1].month_pct <= 0):
                    pct_sum += df.iloc[-1*count - 1].month_pct
                    count += 1
            except IndexError:
                pass

            raw_df.loc[index, 'inc_num'] = -1 * count
            raw_df.loc[index, 'pct_sum'] = pct_sum
    return df